
$Component=function(){
	this.configs = new HashMap();
	this.initComponents();
};

$Component.prototype.initComponents=function(){
	var onlyCode = {
		    displayField: "code",
		    valueField :"code",
		    typeAhead: true,
		    mode: 'local',
		    triggerAction: 'all',
		    emptyText:'...',
		    allowBlank:true,
			editable: false,
			valueSeparator:',',
			forceSelection: false
	};
	codeText = Ext.apply({}, {displayField:'text'}, onlyCode);
	this.configs.put("onlyCode", onlyCode );
	this.configs.put("codeText", codeText );
	this.configs.put("comboCode", Ext.apply({}, {xtype:'combo'}, onlyCode) );
	this.configs.put("comboText", Ext.apply({}, {xtype:'combo'}, codeText) );
	this.configs.put("multiCode", Ext.apply({}, {xtype:'multicombo'}, onlyCode) );
	this.configs.put("multiText", Ext.apply({}, {xtype:'multicombo'}, codeText) );
	this.configs.put("radioCode", Ext.apply({}, {xtype:'radio',inputType:'radio'}, onlyCode) );
	this.configs.put("radioText", Ext.apply({}, {xtype:'radio',inputType:'radio'}, codeText) );
	this.configs.put("checkCode", Ext.apply({}, {xtype:'checkbox',inputType:'checkbox'}, onlyCode) );
	this.configs.put("checkText", Ext.apply({}, {xtype:'checkbox',inputType:'checkbox'}, codeText) );

};

$Component.prototype.addConfig=function(editMode,editConfig){
	this.configs.put(editMode,editConfig);
},
/*public
 * editMode: will be used in xml config file;
 * storeName is the name in $dataStore
 * baseConfig: also is a editMode, should have been stored in the $component;
 * editConfig: special config in the xml config file;
 * */
$Component.prototype.add=function(editMode,storeName,baseConfig,editConfig){
	var myConfig = Ext.apply({}, {store:$dataStore.get(storeName)}, this.configs.get(baseConfig) ) ;
	myConfig =  Ext.apply(myConfig,editConfig);
	$component.addConfig(editMode, myConfig );
},

$Component.prototype.genConfig=function(xConfig,value,validator){
	var name = xConfig.name;
	var fldConfig = {};
		fldConfig.hiddenName=name+"_Hd";
		fldConfig.applyTo=name+"_Id";
		fldConfig.value=value;
		fldConfig.valid=validator;
		//fldConfig.validator=validator;//validator is the key work in ext.
	return Ext.apply(fldConfig,xConfig,this.configs.get(xConfig.editMode));
};

$Component.prototype.genUI=function(xConfig){
	var objUI=Ext.ComponentMgr.create(xConfig);
	if( typeof(xConfig.valid)=="function" ){
		objUI.on('beforeselect',xConfig.valid);
	}
	return objUI;
};

$component = new $Component();

